//index.js
//获取应用实例
const app = getApp()

Page({
  data: {
    autoplay: true,
    interval: 3500,
    duration: 1500,
    userInfo: {},
    hasUserInfo: false,
    canIUse: wx.canIUse('button.open-type.getUserInfo'),
    "bnrUrl": [{
      "id":1,
      "url": "../../images/banner1.jpg"
    }, {
        "id":2,
        "url": "../../images/banner2.jpg"
      }, {
        "id":3,
        "url": "../../images/banner3.jpg"
      }, {
        "id": 4,
        "url": "../../images/banner1.jpg"
      }, {
        "id": 5,
        "url": "../../images/banner2.jpg"
      }, {
        "id": 6,
        "url": "../../images/banner3.jpg"
      }],
    swiperCurrent: 0, 
    

    "items": [
      {
        "id": "1",
        "imageUrl": "http://www.classicliving.com.cn/imageRepository/4b89462c-8613-4045-9e9f-8a82a077a698.jpg",
        "content": ""
      },
      {
        "id": "2",
        "imageUrl": "http://www.51bjjj.com/admin/products_pic/xpic/938_cj_576_360.jpg",
        "content": ""
      },
      {
        "id": "3",
        "imageUrl": "http://www.classicliving.com.cn/imageRepository/8e3b48c5-638b-4760-bce9-087f4061df7b.jpg",
        "content": ""
      },
      {
        "id": "4",
        "imageUrl": "http://www.classicliving.com.cn/imageRepository/fb3174a4-f203-488a-87de-b0a8fa965c4d.jpg",
        "content": ""
      },
      {
        "id": "5",
        "imageUrl": "http://www.51bjjj.com/admin/products_pic/xpic/2522_db_1270_950.jpg",
        "content": ""
      },
      {
        "id": "6",
        "imageUrl": "http://www.51bjjj.com/admin/products_pic/xpic/946_cj_576_360.jpg",
        "content": ""
      },
      {
        "id": "7",
        "imageUrl": "http://www.51bjjj.com/admin/products_pic/xpic/2673_cj_580_404.jpg",
        "content": ""
      },
      {
        "id": "8",
        "imageUrl": "http://www.51bjjj.com/admin/products_pic/xpic/932_cj_576_360.jpg",
        "content": ""
      },
      {
        "id": "9",
        "imageUrl": "http://www.51bjjj.com/admin/products_pic/xpic/928_cj_576_360.jpg",
        "content": ""
      },
      {
        "id": "10",
        "imageUrl": "http://www.51bjjj.com/admin/products_pic/xpic/945_cj_580_404.jpg",
        "content": ""
      },
      {
        "id": "11",
        "imageUrl": "http://www.classicliving.com.cn/imageRepository/a500ac56-7d39-47d8-a7b2-fd3836b82389.jpg",
        "content": ""
      },
      {
        "id": "12",
        "imageUrl": "http://www.51bjjj.com/admin/products_pic/xpic/934_cj_576_360.jpg",
        "content": ""
      }
    ]

  },
  
  //事件处理函数
  swiperchange: function (e) {
    this.setData({
      swiperCurrent: e.detail.current
    })
  },
  onLoad: function () {
    wx.setNavigationBarTitle({
      title: '别墅家具馆',
    })
    if (app.globalData.userInfo) {
      this.setData({
        userInfo: app.globalData.userInfo,
        hasUserInfo: true
      })
    } else if (this.data.canIUse){
      // 由于 getUserInfo 是网络请求，可能会在 Page.onLoad 之后才返回
      // 所以此处加入 callback 以防止这种情况
      app.userInfoReadyCallback = res => {
        this.setData({
          userInfo: res.userInfo,
          hasUserInfo: true
        })
      }
    } else {
      // 在没有 open-type=getUserInfo 版本的兼容处理
      wx.getUserInfo({
        success: res => {
          app.globalData.userInfo = res.userInfo
          this.setData({
            userInfo: res.userInfo,
            hasUserInfo: true
          })
        }
      })
    }
  },
  getUserInfo: function(e) {
    console.log(e)
    app.globalData.userInfo = e.detail.userInfo
    this.setData({
      userInfo: e.detail.userInfo,
      hasUserInfo: true
    })
  }
  
  
})
